﻿using mozhi.smarterp.Finance.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mozhi.smarterp.Finance.Querys
{
    public class DimensionGroupValuePageQuery : PageQuery
    {
        public List<DimensionGroupValueItemQuery> Items { set; get; }

        public List<string> ItemValues { set; get; }

        public string UniqueValue
        {
            get
            {
                if (Items == null)
                    return null;

                if (Items.Count == 0)
                    return "[]";

                List<KeyValuePair<string, string>> dit = new List<KeyValuePair<string, string>>();

                foreach (var item in Items)
                {
                    if (item.DataSourceType != DataSourceType.Tag)
                        dit.Add(new KeyValuePair<string, string>(item.DataSourceType.ToString(), item.Value?.ToLower()));
                    else
                        dit.Add(new KeyValuePair<string, string>(item.TagId.ToString().ToLower(), item.Value?.ToLower()));
                }

                //排序
                dit = dit.OrderBy(x => x.Key).ToList();

                return JsonConvert.SerializeObject(dit);
            }
        }
    }

    public class DimensionGroupValueItemQuery
    {
        public DataSourceType DataSourceType { set; get; }

        public Guid? TagId { set; get; }


        public string Value { set; get; }
    }
}
